#!/usr/bin/env python

import sys
from Tkinter import *
from PIL import Image, ImageTk

root = Tk()
root.title(sys.argv[1])
root.attributes('-zoomed', '1')

image = Image.open(sys.argv[1])
photo = ImageTk.PhotoImage(image)

frame = Frame(root)
frame.pack(fill=BOTH, expand=1)

label = Label(frame, image=photo, bg='black')
label.image = photo
label.pack(fill=BOTH, expand=1)

def config(e):
	width_scale = e.width / float(image.size[0])
	height_scale = e.height / float(image.size[1])

	if width_scale < height_scale:
		new_width = int(image.size[0] * width_scale)
		new_height = int(image.size[1] * width_scale)
	else:
		new_width = int(image.size[0] * height_scale)
		new_height = int(image.size[1] * height_scale)

	global photo
	photo = ImageTk.PhotoImage(image.resize((new_width, new_height), Image.ANTIALIAS))
	label.configure(image=photo)
	label.image = photo

frame.bind('<Configure>', config)
root.mainloop()

